import * as types from '../constants/ActionTypes';

export default function device(state = [], action = {}) {
  const {
        type, payload
    } = action;

  switch (type) {
        case types.SAVE_DEVICEINFO:
            return { ...payload };
        case types.SAVE_DEVICEINFO_SUCCESS:
            let successInfo ;
            if (payload.results && payload.results.length) {
                successInfo = {
                    device_status : 1,
                    message : "保存用户设备信息成功"
                };
            }else{
                successInfo =  {
                    device_status: -1,
                    message: "保存用户设备信息失败"
                };
            }
            return {
                ...state,
                ...successInfo
            };
        case types.SAVE_DEVICEINFO_FAILURE:
            let failureInfo = {
                device_status: -1,
                message: payload.message||'网络连接失败'
            };
            return {
               ...state,
               ...failureInfo
            }; 
        default:
            return state;
    }
}
